package com.bignippleboy.recordthelife.overlay;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;

import com.bignippleboy.recordthelife.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class ImageOverlay extends Overlay {

	private GeoPoint geoPoint;
	private Context context;
	private int drawable;
	private String path = "";
	private Bitmap mBit;

	private Matrix mMatrix = new Matrix();

	public ImageOverlay(GeoPoint geoPoint, Context context, int drawable,
			String path) {
		super();
		this.geoPoint = geoPoint;
		this.context = context;
		this.drawable = drawable;
		this.path = path;

		BitmapFactory.Options opts = new BitmapFactory.Options();
		opts.inSampleSize = 4;
		if (path == null || path == "")
			mBit = BitmapFactory.decodeResource(context.getResources(),
					R.drawable.beauty);
		else
			mBit = BitmapFactory.decodeFile(path, opts);
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		// TODO Auto-generated method stub
		super.draw(canvas, mapView, shadow);
		Projection projection = mapView.getProjection();
		Point point = new Point();
		projection.toPixels(geoPoint, point);

		if (mBit != null) {
			mMatrix.setScale(50f / mBit.getWidth(), 50f / mBit.getHeight());
			mMatrix.postTranslate(point.x - 25, point.y - 25);
			canvas.drawBitmap(mBit, mMatrix, null);
		}
	}

}
